#pragma once
#include<queue>
#include<mutex>
#include<condition_variable>
#include"mysqlConn.h"
#include<memory>

class ConnectionPool
{
public:
    static ConnectionPool *getConnectionPool();

    //  MySqlConn* getConnection();

    shared_ptr<MySqlConn> getConnection();
    ~ConnectionPool();

private:
    ConnectionPool();
    ConnectionPool(const ConnectionPool &) = delete;
    ConnectionPool &operator=(const ConnectionPool &) = delete;
    void produceConnection();
    void recycleConnection();
    // 创建一个连接
    void addConnection();
    void ParseJsonFile();



    string m_ip;
    string m_user;
    string m_password;
    string m_dbname;
    unsigned short m_port;
    int m_minSize;
    int m_maxSize;

    int m_timeout;
    int m_maxIdleTime;
    mutex m_mutex;
    condition_variable m_cond;
    queue<MySqlConn*> m_connectionQ;
};